package com.oig.sys.auth.dto;

import com.oig.common.validator.EnumValue;
import com.oig.common.validator.GroupAdd;
import com.oig.common.validator.GroupEdit;
import com.oig.sys.auth.constants.AuthEnums;
import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@Schema(description = "菜单数据权限配置")
@Data
public class ResourceDataCfgDto {

    @Schema(description = "主键id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "参数错误,id不能为空", groups= GroupEdit.class)
    private Integer id;

    @Schema(description = "所属菜单id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "参数错误,所属菜单id不能为空", groups= {GroupAdd.class, GroupEdit.class})
    private Integer resourceId;

    @Schema(description = "限定用户范围类型：0-按角色限定 1-按岗位限定 2-按部门限定",allowableValues = "0,1,2", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotEmpty(message = "参数错误，限定范围类型必选", groups={GroupAdd.class, GroupEdit.class})
    @EnumValue(message = "限定范围类型值不正确",enumClass = AuthEnums.DataCfgUserLimitType.class, enumValidMethod = "validCode", groups={GroupAdd.class, GroupEdit.class})
    private String userRelationType;

    @Schema(description = "限定用户范围关联id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "参数错误,限定范围必选", groups= {GroupAdd.class, GroupEdit.class})
    private Integer userRelationId;

    @Schema(description = "数据过滤类型：0-按用户id匹配 9-自定义sql", allowableValues = "0,9", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotEmpty(message = "参数错误，数据过滤类型必选", groups={GroupAdd.class, GroupEdit.class})
    @EnumValue(message = "数据过滤类型值不正确",enumClass = AuthEnums.DataCfgEqType.class, enumValidMethod = "validCode", groups={GroupAdd.class, GroupEdit.class})
    private String dataEqType;

    @Schema(description = "数据过滤类型=0时填写，用户id对应的字段 从资源数据列表里选择column_field")
    private String dataEqFiled;

    /**
     * 通用查询怎么拼上这点sql
     */
    @Schema(description = "限定值或sql模板 type=1时填值，type=9时填条件sql")
    private String dataEqSql;

    @Schema(description = "限定用户开放权限白名单,格式：[{\"id\":\"1\",\"name\":\"admin\"}]")
    private String whitelist;

    @Schema(description = "无权限列，json数组格式[\"c1\",\"c2\"]")
    private String excludeField;

    @Schema(description = "所属租户id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotNull(message = "参数错误,所属租户id不能为空", groups= {GroupAdd.class, GroupEdit.class})
    private Integer tenantId;
    @Schema(description = "租户编码")
    private String tenantCode;
    @Schema(description = "所属租户名称", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
//    @NotEmpty(message = "参数错误，所属租户必选", groups={GroupAdd.class, GroupEdit.class})
    private String tenantName;
}
